const request = function (method, url, data) {
  // let baseUrl =`https://${globalData.isDev ? 'kongdev.meb.im' : 'apigate.meb.com'}/biz/outside`
  let baseUrl = ""
	return new Promise((resolve, reject) => {
		let isFullUrl = url.match(/^http[s]?:\/\//),
			reqUrl = isFullUrl ? url : baseUrl + url,
			header = app.getHeader();

		wx.request({
			url: reqUrl,
			data: data || {},
			method: method,
			header: {

			},
			success(res) {
				// console.log(res, '返回res')
				let statusCode = res.statusCode, //接口返回状态码
					isSuccess = res.data.success || res.data.Success; //新网关返回状态(新增大驼峰是为兼容运管接口)

				//接口返回状态正常
				if (statusCode === 200 && isSuccess) {
					if (res.data.code == 401) {
						//限流打开登录
						// _throttle.login();
					}
					resolve(res);
				}
				//请求状态为401未授权
				else if (statusCode === 401) {
					console.error(url, res);
					//限流打开登录
					// _throttle.login();
				}
				//接口返回状态为其他异常
				else {
					console.error(url, res);
					reject(res);
				}
			},
			fail(res) {
				console.error(url, res);
				res.failReason = '小程序发起请求失败';
				reject(res);
			},
		})
	})
};

module.exports = {
  request
}